{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import os\n",
    "import re\n",
    "import pandas as pd\n",
    "import scipy.sparse as sp\n",
    "import torch as th\n",
    "\n",
    "import dgl\n",
    "from dgl.data.utils import download, extract_archive, get_download_dir\n",
    "\n",
    "from itertools import product\n",
    "from collections import Counter\n",
    "from copy import deepcopy\n",
    "from sklearn.model_selection import KFold\n",
    "from tqdm import tqdm\n",
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "import random\n",
    "random.seed(1234)\n",
    "np.random.seed(1234)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_data(directory):\n",
    "    D_SSM = np.loadtxt(directory + '/D_SM.txt')\n",
    "\n",
    "\n",
    "    M_FSM = np.loadtxt(directory + '/M_SM.txt')\n",
    "\n",
    "    print('D_SSM',D_SSM)\n",
    "    print('M_FSM',M_FSM)\n",
    "\n",
    "    ID = np.zeros(shape=(D_SSM.shape[0], D_SSM.shape[1]))\n",
    "    IM = np.zeros(shape=(M_FSM.shape[0], M_FSM.shape[1]))\n",
    "    for i in range(D_SSM.shape[0]):\n",
    "        for j in range(D_SSM.shape[1]):\n",
    "            if D_SSM[i][j] == 0:\n",
    "                ID[i][j] = D_GSM[i][j]###\n",
    "            else:\n",
    "                ID[i][j] = D_SSM[i][j]\n",
    "    for i in range(M_FSM.shape[0]):\n",
    "        for j in range(M_FSM.shape[1]):\n",
    "            if M_FSM[i][j] == 0:\n",
    "                IM[i][j] = M_GSM[i][j]##3\n",
    "            else:\n",
    "                IM[i][j] = M_FSM[i][j]\n",
    "                \n",
    "    ID = pd.DataFrame(ID).reset_index()\n",
    "    IM = pd.DataFrame(IM).reset_index()\n",
    "    print('ID',ID)\n",
    "    print('IM',IM)\n",
    "    ID.rename(columns = {'index':'id'}, inplace = True)\n",
    "    IM.rename(columns = {'index':'id'}, inplace = True)\n",
    "    ID['id'] = ID['id'] + 1\n",
    "    IM['id'] = IM['id'] + 1\n",
    "    print('ID',ID)\n",
    "    print('IM',IM)\n",
    "    #print(ID.shape)\n",
    "    #print(IM.shape)\n",
    "    return ID, IM\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sample(directory, random_seed):\n",
    "    all_associations = pd.read_csv(directory + '/drug_mutation_pairs.csv', names=['Drug', 'Mutation', 'label'])\n",
    "    known_associations = all_associations.loc[all_associations['label'] == 1]\n",
    "    unknown_associations = all_associations.loc[all_associations['label'] == 0]\n",
    "    random_negative = unknown_associations.sample(n=known_associations.shape[0], random_state=random_seed, axis=0)\n",
    "\n",
    "    sample_df = known_associations.append(random_negative)\n",
    "    sample_df.reset_index(drop=True, inplace=True)\n",
    "    #print(sample_df)\n",
    "                 \n",
    "    return sample_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "def obtain_data(directory, isbalance):\n",
    "    ID, IM = load_data(directory)\n",
    "    \n",
    "    if isbalance:\n",
    "        dtp = sample(directory, random_seed = 1234)\n",
    "    else:\n",
    "        dtp = pd.read_csv(directory + '/drug_mutation_pairs.csv', names=['Drug', 'Mutation', 'label'])\n",
    "        \n",
    "    mirna_ids = list(set(dtp['Drug']))\n",
    "    disease_ids = list(set(dtp['Mutation']))\n",
    "    \n",
    "    print('mirna_ids',len(mirna_ids))\n",
    "    print('disease_ids',len(disease_ids))\n",
    "    random.shuffle(mirna_ids)\n",
    "    random.shuffle(disease_ids)\n",
    "    print('# Drug = {} | Mutation = {}'.format(len(mirna_ids), len(disease_ids)))\n",
    "\n",
    "    mirna_test_num = int(len(mirna_ids) / 5)\n",
    "    disease_test_num = int(len(disease_ids) / 5)\n",
    "    print('# Test: Drug = {} | Mutation = {}'.format(mirna_test_num, disease_test_num))\n",
    "   \n",
    "    knn_x = pd.merge(pd.merge(dtp, ID, left_on = 'Drug', right_on = 'id'), IM, left_on = 'Mutation', right_on = 'id')\n",
    "    #print('knn_x',knn_x)\n",
    "    label = dtp['label']\n",
    "    knn_x.drop(labels = ['Drug', 'Mutation', 'label', 'id_x', 'id_y'], axis = 1, inplace = True)\n",
    "    assert ID.shape[0] + IM.shape[0] == knn_x.shape[1]\n",
    "    #print(knn_x.shape, Counter(label))\n",
    "    #print(label.shape)\n",
    "    return ID, IM, dtp, mirna_ids, disease_ids, mirna_test_num, disease_test_num, knn_x, label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "def generate_task_Tp_train_test_idx(knn_x):\n",
    "    kf = KFold(n_splits = 5, shuffle = True, random_state = 1234)\n",
    "\n",
    "    train_index_all, test_index_all, n = [], [], 0\n",
    "    train_id_all, test_id_all = [], []\n",
    "    fold = 0\n",
    "    for train_idx, test_idx in tqdm(kf.split(knn_x)): \n",
    "        print('-------Fold ', fold)\n",
    "        train_index_all.append(train_idx) \n",
    "        test_index_all.append(test_idx)\n",
    "\n",
    "        train_id_all.append(np.array(dtp.iloc[train_idx][['Drug', 'Mutation']]))\n",
    "        test_id_all.append(np.array(dtp.iloc[test_idx][['Drug', 'Mutation']]))\n",
    "\n",
    "        print('# Pairs: Train = {} | Test = {}'.format(len(train_idx), len(test_idx)))\n",
    "        fold += 1\n",
    "    return train_index_all, test_index_all, train_id_all, test_id_all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "def generate_task_Tm_Td_train_test_idx(item, ids, dtp):\n",
    "    \n",
    "    test_num = int(len(ids) / 5)\n",
    "    \n",
    "    train_index_all, test_index_all = [], []\n",
    "    train_id_all, test_id_all = [], []\n",
    "    \n",
    "    for fold in range(5):\n",
    "        print('-------Fold ', fold)\n",
    "        if fold != 4:\n",
    "            test_ids = ids[fold * test_num : (fold + 1) * test_num]\n",
    "        else:\n",
    "            test_ids = ids[fold * test_num :]\n",
    "\n",
    "        train_ids = list(set(ids) ^ set(test_ids))\n",
    "        print('# {}: Train = {} | Test = {}'.format(item, len(train_ids), len(test_ids)))\n",
    "\n",
    "        test_idx = dtp[dtp[item].isin(test_ids)].index.tolist()\n",
    "        train_idx = dtp[dtp[item].isin(train_ids)].index.tolist()\n",
    "        random.shuffle(test_idx)\n",
    "        random.shuffle(train_idx)\n",
    "        print('# Pairs: Train = {} | Test = {}'.format(len(train_idx), len(test_idx)))\n",
    "        assert len(train_idx) + len(test_idx) == len(dtp)\n",
    "\n",
    "        train_index_all.append(train_idx) \n",
    "        test_index_all.append(test_idx)\n",
    "        \n",
    "        train_id_all.append(train_ids)\n",
    "        test_id_all.append(test_ids)\n",
    "        \n",
    "    return train_index_all, test_index_all, train_id_all, test_id_all"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# KNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.neighbors import KNeighborsClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "from sklearn.metrics import roc_auc_score, auc\n",
    "from sklearn.metrics import precision_recall_fscore_support\n",
    "from sklearn.metrics import precision_recall_curve\n",
    "from sklearn.metrics import classification_report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "def generate_knn_graph_save(knn_x, label, n_neigh, train_index_all, test_index_all, pwd, task, balance):\n",
    "    \n",
    "    fold = 0\n",
    "    for train_idx, test_idx in zip(train_index_all, test_index_all): \n",
    "        print('-------Fold ', fold)\n",
    "        \n",
    "        knn_y = deepcopy(label)  ###label\n",
    "        knn_y[test_idx] = 0\n",
    "        print('Label: ', Counter(label))\n",
    "        print('knn_y: ', Counter(knn_y))\n",
    "\n",
    "        knn = KNeighborsClassifier(n_neighbors = n_neigh)\n",
    "        knn.fit(knn_x, knn_y)\n",
    "\n",
    "        knn_y_pred = knn.predict(knn_x)\n",
    "        knn_y_prob = knn.predict_proba(knn_x)\n",
    "        knn_neighbors_graph = knn.kneighbors_graph(knn_x, n_neighbors = n_neigh)\n",
    "\n",
    "\n",
    "        sp.save_npz(pwd + 'task_' + task + balance + '__testlabel0_knn' + str(n_neigh) + 'neighbors_edge__fold' + str(fold) + '.npz', knn_neighbors_graph)\n",
    "        fold += 1\n",
    "    return knn_x, knn_y, knn, knn_neighbors_graph"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "************isbalance =  True\n",
      "=================task =  Tp\n",
      "D_SSM [[1.         0.89766196 0.9695392  ... 0.93836794 0.94563883 0.93286166]\n",
      " [0.89766196 1.         0.97386686 ... 0.99178252 0.98852405 0.9811674 ]\n",
      " [0.9695392  0.97386686 1.         ... 0.98927445 0.9959657  0.98758327]\n",
      " ...\n",
      " [0.93836794 0.99178252 0.98927445 ... 1.         0.9946604  0.9929528 ]\n",
      " [0.94563883 0.98852405 0.9959657  ... 0.9946604  1.         0.99153622]\n",
      " [0.93286166 0.9811674  0.98758327 ... 0.9929528  0.99153622 1.        ]]\n",
      "M_FSM [[1.         0.90766937 0.17608963 ... 0.89524413 0.01611704 0.03146066]\n",
      " [0.90766937 1.         0.0183536  ... 0.97583942 0.08079069 0.07906328]\n",
      " [0.17608963 0.0183536  1.         ... 0.04580561 0.83450014 0.84573587]\n",
      " ...\n",
      " [0.89524413 0.97583942 0.04580561 ... 1.         0.10737693 0.12459924]\n",
      " [0.01611704 0.08079069 0.83450014 ... 0.10737693 1.         0.99315765]\n",
      " [0.03146066 0.07906328 0.84573587 ... 0.12459924 0.99315765 1.        ]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "5it [00:00, 557.06it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ID      index         0         1         2         3         4         5  \\\n",
      "0        0  1.000000  0.897662  0.969539  0.977718  0.895714  0.955645   \n",
      "1        1  0.897662  1.000000  0.973867  0.967525  0.998237  0.974889   \n",
      "2        2  0.969539  0.973867  1.000000  0.997122  0.973182  0.986712   \n",
      "3        3  0.977718  0.967525  0.997122  1.000000  0.964158  0.991381   \n",
      "4        4  0.895714  0.998237  0.973182  0.964158  1.000000  0.966592   \n",
      "..     ...       ...       ...       ...       ...       ...       ...   \n",
      "179    179  0.862918  0.675884  0.775158  0.802688  0.655391  0.796309   \n",
      "180    180  0.973597  0.972996  0.994931  0.997336  0.970741  0.991165   \n",
      "181    181  0.938368  0.991783  0.989274  0.984975  0.992872  0.980042   \n",
      "182    182  0.945639  0.988524  0.995966  0.991062  0.987236  0.986661   \n",
      "183    183  0.932862  0.981167  0.987583  0.978269  0.986323  0.962156   \n",
      "\n",
      "            6         7         8  ...       174       175       176  \\\n",
      "0    0.946404  0.989230  0.885793  ...  0.981128  0.981633  0.938121   \n",
      "1    0.990946  0.900367  0.992380  ...  0.892665  0.895908  0.813548   \n",
      "2    0.994273  0.963344  0.967592  ...  0.966367  0.959415  0.885173   \n",
      "3    0.990337  0.977575  0.954821  ...  0.972319  0.973149  0.905176   \n",
      "4    0.990725  0.890795  0.997502  ...  0.887712  0.885108  0.801731   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "179  0.738956  0.892354  0.626119  ...  0.847433  0.868224  0.956633   \n",
      "180  0.992870  0.970224  0.961541  ...  0.956411  0.962710  0.902469   \n",
      "181  0.998560  0.931316  0.989023  ...  0.925891  0.923723  0.857679   \n",
      "182  0.997835  0.944274  0.981751  ...  0.947118  0.939886  0.864105   \n",
      "183  0.991868  0.916459  0.988846  ...  0.931578  0.912692  0.831499   \n",
      "\n",
      "          177       178       179       180       181       182       183  \n",
      "0    0.923775  0.985842  0.862918  0.973597  0.938368  0.945639  0.932862  \n",
      "1    0.790636  0.883018  0.675884  0.972996  0.991783  0.988524  0.981167  \n",
      "2    0.864696  0.961228  0.775158  0.994931  0.989274  0.995966  0.987583  \n",
      "3    0.891424  0.969715  0.802688  0.997336  0.984975  0.991062  0.978269  \n",
      "4    0.768920  0.877347  0.655391  0.970741  0.992872  0.987236  0.986323  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "179  0.942702  0.858934  1.000000  0.791763  0.727605  0.745174  0.696908  \n",
      "180  0.883940  0.955488  0.791763  1.000000  0.989882  0.989944  0.979530  \n",
      "181  0.820336  0.919242  0.727605  0.989882  1.000000  0.994660  0.992953  \n",
      "182  0.839641  0.938761  0.745174  0.989944  0.994660  1.000000  0.991536  \n",
      "183  0.782923  0.922494  0.696908  0.979530  0.992953  0.991536  1.000000  \n",
      "\n",
      "[184 rows x 185 columns]\n",
      "IM      index         0         1         2         3         4         5  \\\n",
      "0        0  1.000000  0.907669  0.176090  0.702117  0.286608  0.490720   \n",
      "1        1  0.907669  1.000000  0.018354  0.921630  0.071288  0.220028   \n",
      "2        2  0.176090  0.018354  1.000000  0.022731  0.981050  0.879705   \n",
      "3        3  0.702117  0.921630  0.022731  1.000000  0.001701  0.042796   \n",
      "4        4  0.286608  0.071288  0.981050  0.001701  1.000000  0.952651   \n",
      "..     ...       ...       ...       ...       ...       ...       ...   \n",
      "656    656  0.399699  0.146881  0.933354  0.012895  0.983124  0.988453   \n",
      "657    657  0.170419  0.045495  0.956196  0.078107  0.926840  0.814243   \n",
      "658    658  0.895244  0.975839  0.045806  0.894017  0.099658  0.246381   \n",
      "659    659  0.016117  0.080791  0.834500  0.285888  0.722721  0.516941   \n",
      "660    660  0.031461  0.079063  0.845736  0.264039  0.740647  0.546501   \n",
      "\n",
      "            6         7         8  ...       651       652       653  \\\n",
      "0    0.719039  0.970476  0.852814  ...  0.018562  0.262593  0.080250   \n",
      "1    0.444454  0.974827  0.867932  ...  0.049907  0.506563  0.238188   \n",
      "2    0.684846  0.083677  0.195105  ...  0.876980  0.370412  0.650142   \n",
      "3    0.188250  0.817615  0.711285  ...  0.234733  0.753886  0.483892   \n",
      "4    0.803060  0.173261  0.276134  ...  0.775504  0.257325  0.525321   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "656  0.888592  0.274203  0.372869  ...  0.668887  0.180138  0.424284   \n",
      "657  0.622768  0.091308  0.197611  ...  0.891163  0.500563  0.749689   \n",
      "658  0.461533  0.956461  0.852942  ...  0.076113  0.548616  0.291475   \n",
      "659  0.282391  0.018094  0.093945  ...  0.995184  0.753412  0.942234   \n",
      "660  0.314889  0.025820  0.105386  ...  0.987390  0.741837  0.940644   \n",
      "\n",
      "          654       655       656       657       658       659       660  \n",
      "0    0.547275  0.022780  0.399699  0.170419  0.895244  0.016117  0.031461  \n",
      "1    0.808724  0.074212  0.146881  0.045495  0.975839  0.080791  0.079063  \n",
      "2    0.098734  0.846843  0.933354  0.956196  0.045806  0.834500  0.845736  \n",
      "3    0.970415  0.269916  0.012895  0.078107  0.894017  0.285888  0.264039  \n",
      "4    0.035068  0.740986  0.983124  0.926840  0.099658  0.722721  0.740647  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "656  0.008320  0.635777  1.000000  0.883281  0.181613  0.613177  0.642788  \n",
      "657  0.178040  0.889241  0.883281  1.000000  0.126786  0.859227  0.887914  \n",
      "658  0.794568  0.118486  0.181613  0.126786  1.000000  0.107377  0.124599  \n",
      "659  0.449486  0.995092  0.613177  0.859227  0.107377  1.000000  0.993158  \n",
      "660  0.424641  0.993029  0.642788  0.887914  0.124599  0.993158  1.000000  \n",
      "\n",
      "[661 rows x 662 columns]\n",
      "ID       id         0         1         2         3         4         5  \\\n",
      "0      1  1.000000  0.897662  0.969539  0.977718  0.895714  0.955645   \n",
      "1      2  0.897662  1.000000  0.973867  0.967525  0.998237  0.974889   \n",
      "2      3  0.969539  0.973867  1.000000  0.997122  0.973182  0.986712   \n",
      "3      4  0.977718  0.967525  0.997122  1.000000  0.964158  0.991381   \n",
      "4      5  0.895714  0.998237  0.973182  0.964158  1.000000  0.966592   \n",
      "..   ...       ...       ...       ...       ...       ...       ...   \n",
      "179  180  0.862918  0.675884  0.775158  0.802688  0.655391  0.796309   \n",
      "180  181  0.973597  0.972996  0.994931  0.997336  0.970741  0.991165   \n",
      "181  182  0.938368  0.991783  0.989274  0.984975  0.992872  0.980042   \n",
      "182  183  0.945639  0.988524  0.995966  0.991062  0.987236  0.986661   \n",
      "183  184  0.932862  0.981167  0.987583  0.978269  0.986323  0.962156   \n",
      "\n",
      "            6         7         8  ...       174       175       176  \\\n",
      "0    0.946404  0.989230  0.885793  ...  0.981128  0.981633  0.938121   \n",
      "1    0.990946  0.900367  0.992380  ...  0.892665  0.895908  0.813548   \n",
      "2    0.994273  0.963344  0.967592  ...  0.966367  0.959415  0.885173   \n",
      "3    0.990337  0.977575  0.954821  ...  0.972319  0.973149  0.905176   \n",
      "4    0.990725  0.890795  0.997502  ...  0.887712  0.885108  0.801731   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "179  0.738956  0.892354  0.626119  ...  0.847433  0.868224  0.956633   \n",
      "180  0.992870  0.970224  0.961541  ...  0.956411  0.962710  0.902469   \n",
      "181  0.998560  0.931316  0.989023  ...  0.925891  0.923723  0.857679   \n",
      "182  0.997835  0.944274  0.981751  ...  0.947118  0.939886  0.864105   \n",
      "183  0.991868  0.916459  0.988846  ...  0.931578  0.912692  0.831499   \n",
      "\n",
      "          177       178       179       180       181       182       183  \n",
      "0    0.923775  0.985842  0.862918  0.973597  0.938368  0.945639  0.932862  \n",
      "1    0.790636  0.883018  0.675884  0.972996  0.991783  0.988524  0.981167  \n",
      "2    0.864696  0.961228  0.775158  0.994931  0.989274  0.995966  0.987583  \n",
      "3    0.891424  0.969715  0.802688  0.997336  0.984975  0.991062  0.978269  \n",
      "4    0.768920  0.877347  0.655391  0.970741  0.992872  0.987236  0.986323  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "179  0.942702  0.858934  1.000000  0.791763  0.727605  0.745174  0.696908  \n",
      "180  0.883940  0.955488  0.791763  1.000000  0.989882  0.989944  0.979530  \n",
      "181  0.820336  0.919242  0.727605  0.989882  1.000000  0.994660  0.992953  \n",
      "182  0.839641  0.938761  0.745174  0.989944  0.994660  1.000000  0.991536  \n",
      "183  0.782923  0.922494  0.696908  0.979530  0.992953  0.991536  1.000000  \n",
      "\n",
      "[184 rows x 185 columns]\n",
      "IM       id         0         1         2         3         4         5  \\\n",
      "0      1  1.000000  0.907669  0.176090  0.702117  0.286608  0.490720   \n",
      "1      2  0.907669  1.000000  0.018354  0.921630  0.071288  0.220028   \n",
      "2      3  0.176090  0.018354  1.000000  0.022731  0.981050  0.879705   \n",
      "3      4  0.702117  0.921630  0.022731  1.000000  0.001701  0.042796   \n",
      "4      5  0.286608  0.071288  0.981050  0.001701  1.000000  0.952651   \n",
      "..   ...       ...       ...       ...       ...       ...       ...   \n",
      "656  657  0.399699  0.146881  0.933354  0.012895  0.983124  0.988453   \n",
      "657  658  0.170419  0.045495  0.956196  0.078107  0.926840  0.814243   \n",
      "658  659  0.895244  0.975839  0.045806  0.894017  0.099658  0.246381   \n",
      "659  660  0.016117  0.080791  0.834500  0.285888  0.722721  0.516941   \n",
      "660  661  0.031461  0.079063  0.845736  0.264039  0.740647  0.546501   \n",
      "\n",
      "            6         7         8  ...       651       652       653  \\\n",
      "0    0.719039  0.970476  0.852814  ...  0.018562  0.262593  0.080250   \n",
      "1    0.444454  0.974827  0.867932  ...  0.049907  0.506563  0.238188   \n",
      "2    0.684846  0.083677  0.195105  ...  0.876980  0.370412  0.650142   \n",
      "3    0.188250  0.817615  0.711285  ...  0.234733  0.753886  0.483892   \n",
      "4    0.803060  0.173261  0.276134  ...  0.775504  0.257325  0.525321   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "656  0.888592  0.274203  0.372869  ...  0.668887  0.180138  0.424284   \n",
      "657  0.622768  0.091308  0.197611  ...  0.891163  0.500563  0.749689   \n",
      "658  0.461533  0.956461  0.852942  ...  0.076113  0.548616  0.291475   \n",
      "659  0.282391  0.018094  0.093945  ...  0.995184  0.753412  0.942234   \n",
      "660  0.314889  0.025820  0.105386  ...  0.987390  0.741837  0.940644   \n",
      "\n",
      "          654       655       656       657       658       659       660  \n",
      "0    0.547275  0.022780  0.399699  0.170419  0.895244  0.016117  0.031461  \n",
      "1    0.808724  0.074212  0.146881  0.045495  0.975839  0.080791  0.079063  \n",
      "2    0.098734  0.846843  0.933354  0.956196  0.045806  0.834500  0.845736  \n",
      "3    0.970415  0.269916  0.012895  0.078107  0.894017  0.285888  0.264039  \n",
      "4    0.035068  0.740986  0.983124  0.926840  0.099658  0.722721  0.740647  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "656  0.008320  0.635777  1.000000  0.883281  0.181613  0.613177  0.642788  \n",
      "657  0.178040  0.889241  0.883281  1.000000  0.126786  0.859227  0.887914  \n",
      "658  0.794568  0.118486  0.181613  0.126786  1.000000  0.107377  0.124599  \n",
      "659  0.449486  0.995092  0.613177  0.859227  0.107377  1.000000  0.993158  \n",
      "660  0.424641  0.993029  0.642788  0.887914  0.124599  0.993158  1.000000  \n",
      "\n",
      "[661 rows x 662 columns]\n",
      "mirna_ids 184\n",
      "disease_ids 578\n",
      "# Drug = 184 | Mutation = 578\n",
      "# Test: Drug = 36 | Mutation = 115\n",
      "-------Fold  0\n",
      "# Pairs: Train = 1336 | Test = 334\n",
      "-------Fold  1\n",
      "# Pairs: Train = 1336 | Test = 334\n",
      "-------Fold  2\n",
      "# Pairs: Train = 1336 | Test = 334\n",
      "-------Fold  3\n",
      "# Pairs: Train = 1336 | Test = 334\n",
      "-------Fold  4\n",
      "# Pairs: Train = 1336 | Test = 334\n",
      "--------------------------n_neighbors =  1\n",
      "=================task =  Td\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "D_SSM [[1.         0.89766196 0.9695392  ... 0.93836794 0.94563883 0.93286166]\n",
      " [0.89766196 1.         0.97386686 ... 0.99178252 0.98852405 0.9811674 ]\n",
      " [0.9695392  0.97386686 1.         ... 0.98927445 0.9959657  0.98758327]\n",
      " ...\n",
      " [0.93836794 0.99178252 0.98927445 ... 1.         0.9946604  0.9929528 ]\n",
      " [0.94563883 0.98852405 0.9959657  ... 0.9946604  1.         0.99153622]\n",
      " [0.93286166 0.9811674  0.98758327 ... 0.9929528  0.99153622 1.        ]]\n",
      "M_FSM [[1.         0.90766937 0.17608963 ... 0.89524413 0.01611704 0.03146066]\n",
      " [0.90766937 1.         0.0183536  ... 0.97583942 0.08079069 0.07906328]\n",
      " [0.17608963 0.0183536  1.         ... 0.04580561 0.83450014 0.84573587]\n",
      " ...\n",
      " [0.89524413 0.97583942 0.04580561 ... 1.         0.10737693 0.12459924]\n",
      " [0.01611704 0.08079069 0.83450014 ... 0.10737693 1.         0.99315765]\n",
      " [0.03146066 0.07906328 0.84573587 ... 0.12459924 0.99315765 1.        ]]\n",
      "ID      index         0         1         2         3         4         5  \\\n",
      "0        0  1.000000  0.897662  0.969539  0.977718  0.895714  0.955645   \n",
      "1        1  0.897662  1.000000  0.973867  0.967525  0.998237  0.974889   \n",
      "2        2  0.969539  0.973867  1.000000  0.997122  0.973182  0.986712   \n",
      "3        3  0.977718  0.967525  0.997122  1.000000  0.964158  0.991381   \n",
      "4        4  0.895714  0.998237  0.973182  0.964158  1.000000  0.966592   \n",
      "..     ...       ...       ...       ...       ...       ...       ...   \n",
      "179    179  0.862918  0.675884  0.775158  0.802688  0.655391  0.796309   \n",
      "180    180  0.973597  0.972996  0.994931  0.997336  0.970741  0.991165   \n",
      "181    181  0.938368  0.991783  0.989274  0.984975  0.992872  0.980042   \n",
      "182    182  0.945639  0.988524  0.995966  0.991062  0.987236  0.986661   \n",
      "183    183  0.932862  0.981167  0.987583  0.978269  0.986323  0.962156   \n",
      "\n",
      "            6         7         8  ...       174       175       176  \\\n",
      "0    0.946404  0.989230  0.885793  ...  0.981128  0.981633  0.938121   \n",
      "1    0.990946  0.900367  0.992380  ...  0.892665  0.895908  0.813548   \n",
      "2    0.994273  0.963344  0.967592  ...  0.966367  0.959415  0.885173   \n",
      "3    0.990337  0.977575  0.954821  ...  0.972319  0.973149  0.905176   \n",
      "4    0.990725  0.890795  0.997502  ...  0.887712  0.885108  0.801731   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "179  0.738956  0.892354  0.626119  ...  0.847433  0.868224  0.956633   \n",
      "180  0.992870  0.970224  0.961541  ...  0.956411  0.962710  0.902469   \n",
      "181  0.998560  0.931316  0.989023  ...  0.925891  0.923723  0.857679   \n",
      "182  0.997835  0.944274  0.981751  ...  0.947118  0.939886  0.864105   \n",
      "183  0.991868  0.916459  0.988846  ...  0.931578  0.912692  0.831499   \n",
      "\n",
      "          177       178       179       180       181       182       183  \n",
      "0    0.923775  0.985842  0.862918  0.973597  0.938368  0.945639  0.932862  \n",
      "1    0.790636  0.883018  0.675884  0.972996  0.991783  0.988524  0.981167  \n",
      "2    0.864696  0.961228  0.775158  0.994931  0.989274  0.995966  0.987583  \n",
      "3    0.891424  0.969715  0.802688  0.997336  0.984975  0.991062  0.978269  \n",
      "4    0.768920  0.877347  0.655391  0.970741  0.992872  0.987236  0.986323  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "179  0.942702  0.858934  1.000000  0.791763  0.727605  0.745174  0.696908  \n",
      "180  0.883940  0.955488  0.791763  1.000000  0.989882  0.989944  0.979530  \n",
      "181  0.820336  0.919242  0.727605  0.989882  1.000000  0.994660  0.992953  \n",
      "182  0.839641  0.938761  0.745174  0.989944  0.994660  1.000000  0.991536  \n",
      "183  0.782923  0.922494  0.696908  0.979530  0.992953  0.991536  1.000000  \n",
      "\n",
      "[184 rows x 185 columns]\n",
      "IM      index         0         1         2         3         4         5  \\\n",
      "0        0  1.000000  0.907669  0.176090  0.702117  0.286608  0.490720   \n",
      "1        1  0.907669  1.000000  0.018354  0.921630  0.071288  0.220028   \n",
      "2        2  0.176090  0.018354  1.000000  0.022731  0.981050  0.879705   \n",
      "3        3  0.702117  0.921630  0.022731  1.000000  0.001701  0.042796   \n",
      "4        4  0.286608  0.071288  0.981050  0.001701  1.000000  0.952651   \n",
      "..     ...       ...       ...       ...       ...       ...       ...   \n",
      "656    656  0.399699  0.146881  0.933354  0.012895  0.983124  0.988453   \n",
      "657    657  0.170419  0.045495  0.956196  0.078107  0.926840  0.814243   \n",
      "658    658  0.895244  0.975839  0.045806  0.894017  0.099658  0.246381   \n",
      "659    659  0.016117  0.080791  0.834500  0.285888  0.722721  0.516941   \n",
      "660    660  0.031461  0.079063  0.845736  0.264039  0.740647  0.546501   \n",
      "\n",
      "            6         7         8  ...       651       652       653  \\\n",
      "0    0.719039  0.970476  0.852814  ...  0.018562  0.262593  0.080250   \n",
      "1    0.444454  0.974827  0.867932  ...  0.049907  0.506563  0.238188   \n",
      "2    0.684846  0.083677  0.195105  ...  0.876980  0.370412  0.650142   \n",
      "3    0.188250  0.817615  0.711285  ...  0.234733  0.753886  0.483892   \n",
      "4    0.803060  0.173261  0.276134  ...  0.775504  0.257325  0.525321   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "656  0.888592  0.274203  0.372869  ...  0.668887  0.180138  0.424284   \n",
      "657  0.622768  0.091308  0.197611  ...  0.891163  0.500563  0.749689   \n",
      "658  0.461533  0.956461  0.852942  ...  0.076113  0.548616  0.291475   \n",
      "659  0.282391  0.018094  0.093945  ...  0.995184  0.753412  0.942234   \n",
      "660  0.314889  0.025820  0.105386  ...  0.987390  0.741837  0.940644   \n",
      "\n",
      "          654       655       656       657       658       659       660  \n",
      "0    0.547275  0.022780  0.399699  0.170419  0.895244  0.016117  0.031461  \n",
      "1    0.808724  0.074212  0.146881  0.045495  0.975839  0.080791  0.079063  \n",
      "2    0.098734  0.846843  0.933354  0.956196  0.045806  0.834500  0.845736  \n",
      "3    0.970415  0.269916  0.012895  0.078107  0.894017  0.285888  0.264039  \n",
      "4    0.035068  0.740986  0.983124  0.926840  0.099658  0.722721  0.740647  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "656  0.008320  0.635777  1.000000  0.883281  0.181613  0.613177  0.642788  \n",
      "657  0.178040  0.889241  0.883281  1.000000  0.126786  0.859227  0.887914  \n",
      "658  0.794568  0.118486  0.181613  0.126786  1.000000  0.107377  0.124599  \n",
      "659  0.449486  0.995092  0.613177  0.859227  0.107377  1.000000  0.993158  \n",
      "660  0.424641  0.993029  0.642788  0.887914  0.124599  0.993158  1.000000  \n",
      "\n",
      "[661 rows x 662 columns]\n",
      "ID       id         0         1         2         3         4         5  \\\n",
      "0      1  1.000000  0.897662  0.969539  0.977718  0.895714  0.955645   \n",
      "1      2  0.897662  1.000000  0.973867  0.967525  0.998237  0.974889   \n",
      "2      3  0.969539  0.973867  1.000000  0.997122  0.973182  0.986712   \n",
      "3      4  0.977718  0.967525  0.997122  1.000000  0.964158  0.991381   \n",
      "4      5  0.895714  0.998237  0.973182  0.964158  1.000000  0.966592   \n",
      "..   ...       ...       ...       ...       ...       ...       ...   \n",
      "179  180  0.862918  0.675884  0.775158  0.802688  0.655391  0.796309   \n",
      "180  181  0.973597  0.972996  0.994931  0.997336  0.970741  0.991165   \n",
      "181  182  0.938368  0.991783  0.989274  0.984975  0.992872  0.980042   \n",
      "182  183  0.945639  0.988524  0.995966  0.991062  0.987236  0.986661   \n",
      "183  184  0.932862  0.981167  0.987583  0.978269  0.986323  0.962156   \n",
      "\n",
      "            6         7         8  ...       174       175       176  \\\n",
      "0    0.946404  0.989230  0.885793  ...  0.981128  0.981633  0.938121   \n",
      "1    0.990946  0.900367  0.992380  ...  0.892665  0.895908  0.813548   \n",
      "2    0.994273  0.963344  0.967592  ...  0.966367  0.959415  0.885173   \n",
      "3    0.990337  0.977575  0.954821  ...  0.972319  0.973149  0.905176   \n",
      "4    0.990725  0.890795  0.997502  ...  0.887712  0.885108  0.801731   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "179  0.738956  0.892354  0.626119  ...  0.847433  0.868224  0.956633   \n",
      "180  0.992870  0.970224  0.961541  ...  0.956411  0.962710  0.902469   \n",
      "181  0.998560  0.931316  0.989023  ...  0.925891  0.923723  0.857679   \n",
      "182  0.997835  0.944274  0.981751  ...  0.947118  0.939886  0.864105   \n",
      "183  0.991868  0.916459  0.988846  ...  0.931578  0.912692  0.831499   \n",
      "\n",
      "          177       178       179       180       181       182       183  \n",
      "0    0.923775  0.985842  0.862918  0.973597  0.938368  0.945639  0.932862  \n",
      "1    0.790636  0.883018  0.675884  0.972996  0.991783  0.988524  0.981167  \n",
      "2    0.864696  0.961228  0.775158  0.994931  0.989274  0.995966  0.987583  \n",
      "3    0.891424  0.969715  0.802688  0.997336  0.984975  0.991062  0.978269  \n",
      "4    0.768920  0.877347  0.655391  0.970741  0.992872  0.987236  0.986323  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "179  0.942702  0.858934  1.000000  0.791763  0.727605  0.745174  0.696908  \n",
      "180  0.883940  0.955488  0.791763  1.000000  0.989882  0.989944  0.979530  \n",
      "181  0.820336  0.919242  0.727605  0.989882  1.000000  0.994660  0.992953  \n",
      "182  0.839641  0.938761  0.745174  0.989944  0.994660  1.000000  0.991536  \n",
      "183  0.782923  0.922494  0.696908  0.979530  0.992953  0.991536  1.000000  \n",
      "\n",
      "[184 rows x 185 columns]\n",
      "IM       id         0         1         2         3         4         5  \\\n",
      "0      1  1.000000  0.907669  0.176090  0.702117  0.286608  0.490720   \n",
      "1      2  0.907669  1.000000  0.018354  0.921630  0.071288  0.220028   \n",
      "2      3  0.176090  0.018354  1.000000  0.022731  0.981050  0.879705   \n",
      "3      4  0.702117  0.921630  0.022731  1.000000  0.001701  0.042796   \n",
      "4      5  0.286608  0.071288  0.981050  0.001701  1.000000  0.952651   \n",
      "..   ...       ...       ...       ...       ...       ...       ...   \n",
      "656  657  0.399699  0.146881  0.933354  0.012895  0.983124  0.988453   \n",
      "657  658  0.170419  0.045495  0.956196  0.078107  0.926840  0.814243   \n",
      "658  659  0.895244  0.975839  0.045806  0.894017  0.099658  0.246381   \n",
      "659  660  0.016117  0.080791  0.834500  0.285888  0.722721  0.516941   \n",
      "660  661  0.031461  0.079063  0.845736  0.264039  0.740647  0.546501   \n",
      "\n",
      "            6         7         8  ...       651       652       653  \\\n",
      "0    0.719039  0.970476  0.852814  ...  0.018562  0.262593  0.080250   \n",
      "1    0.444454  0.974827  0.867932  ...  0.049907  0.506563  0.238188   \n",
      "2    0.684846  0.083677  0.195105  ...  0.876980  0.370412  0.650142   \n",
      "3    0.188250  0.817615  0.711285  ...  0.234733  0.753886  0.483892   \n",
      "4    0.803060  0.173261  0.276134  ...  0.775504  0.257325  0.525321   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "656  0.888592  0.274203  0.372869  ...  0.668887  0.180138  0.424284   \n",
      "657  0.622768  0.091308  0.197611  ...  0.891163  0.500563  0.749689   \n",
      "658  0.461533  0.956461  0.852942  ...  0.076113  0.548616  0.291475   \n",
      "659  0.282391  0.018094  0.093945  ...  0.995184  0.753412  0.942234   \n",
      "660  0.314889  0.025820  0.105386  ...  0.987390  0.741837  0.940644   \n",
      "\n",
      "          654       655       656       657       658       659       660  \n",
      "0    0.547275  0.022780  0.399699  0.170419  0.895244  0.016117  0.031461  \n",
      "1    0.808724  0.074212  0.146881  0.045495  0.975839  0.080791  0.079063  \n",
      "2    0.098734  0.846843  0.933354  0.956196  0.045806  0.834500  0.845736  \n",
      "3    0.970415  0.269916  0.012895  0.078107  0.894017  0.285888  0.264039  \n",
      "4    0.035068  0.740986  0.983124  0.926840  0.099658  0.722721  0.740647  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "656  0.008320  0.635777  1.000000  0.883281  0.181613  0.613177  0.642788  \n",
      "657  0.178040  0.889241  0.883281  1.000000  0.126786  0.859227  0.887914  \n",
      "658  0.794568  0.118486  0.181613  0.126786  1.000000  0.107377  0.124599  \n",
      "659  0.449486  0.995092  0.613177  0.859227  0.107377  1.000000  0.993158  \n",
      "660  0.424641  0.993029  0.642788  0.887914  0.124599  0.993158  1.000000  \n",
      "\n",
      "[661 rows x 662 columns]\n",
      "mirna_ids 184\n",
      "disease_ids 578\n",
      "# Drug = 184 | Mutation = 578\n",
      "# Test: Drug = 36 | Mutation = 115\n",
      "--------------------------n_neighbors =  1\n",
      "=================task =  Tm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "D_SSM [[1.         0.89766196 0.9695392  ... 0.93836794 0.94563883 0.93286166]\n",
      " [0.89766196 1.         0.97386686 ... 0.99178252 0.98852405 0.9811674 ]\n",
      " [0.9695392  0.97386686 1.         ... 0.98927445 0.9959657  0.98758327]\n",
      " ...\n",
      " [0.93836794 0.99178252 0.98927445 ... 1.         0.9946604  0.9929528 ]\n",
      " [0.94563883 0.98852405 0.9959657  ... 0.9946604  1.         0.99153622]\n",
      " [0.93286166 0.9811674  0.98758327 ... 0.9929528  0.99153622 1.        ]]\n",
      "M_FSM [[1.         0.90766937 0.17608963 ... 0.89524413 0.01611704 0.03146066]\n",
      " [0.90766937 1.         0.0183536  ... 0.97583942 0.08079069 0.07906328]\n",
      " [0.17608963 0.0183536  1.         ... 0.04580561 0.83450014 0.84573587]\n",
      " ...\n",
      " [0.89524413 0.97583942 0.04580561 ... 1.         0.10737693 0.12459924]\n",
      " [0.01611704 0.08079069 0.83450014 ... 0.10737693 1.         0.99315765]\n",
      " [0.03146066 0.07906328 0.84573587 ... 0.12459924 0.99315765 1.        ]]\n",
      "ID      index         0         1         2         3         4         5  \\\n",
      "0        0  1.000000  0.897662  0.969539  0.977718  0.895714  0.955645   \n",
      "1        1  0.897662  1.000000  0.973867  0.967525  0.998237  0.974889   \n",
      "2        2  0.969539  0.973867  1.000000  0.997122  0.973182  0.986712   \n",
      "3        3  0.977718  0.967525  0.997122  1.000000  0.964158  0.991381   \n",
      "4        4  0.895714  0.998237  0.973182  0.964158  1.000000  0.966592   \n",
      "..     ...       ...       ...       ...       ...       ...       ...   \n",
      "179    179  0.862918  0.675884  0.775158  0.802688  0.655391  0.796309   \n",
      "180    180  0.973597  0.972996  0.994931  0.997336  0.970741  0.991165   \n",
      "181    181  0.938368  0.991783  0.989274  0.984975  0.992872  0.980042   \n",
      "182    182  0.945639  0.988524  0.995966  0.991062  0.987236  0.986661   \n",
      "183    183  0.932862  0.981167  0.987583  0.978269  0.986323  0.962156   \n",
      "\n",
      "            6         7         8  ...       174       175       176  \\\n",
      "0    0.946404  0.989230  0.885793  ...  0.981128  0.981633  0.938121   \n",
      "1    0.990946  0.900367  0.992380  ...  0.892665  0.895908  0.813548   \n",
      "2    0.994273  0.963344  0.967592  ...  0.966367  0.959415  0.885173   \n",
      "3    0.990337  0.977575  0.954821  ...  0.972319  0.973149  0.905176   \n",
      "4    0.990725  0.890795  0.997502  ...  0.887712  0.885108  0.801731   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "179  0.738956  0.892354  0.626119  ...  0.847433  0.868224  0.956633   \n",
      "180  0.992870  0.970224  0.961541  ...  0.956411  0.962710  0.902469   \n",
      "181  0.998560  0.931316  0.989023  ...  0.925891  0.923723  0.857679   \n",
      "182  0.997835  0.944274  0.981751  ...  0.947118  0.939886  0.864105   \n",
      "183  0.991868  0.916459  0.988846  ...  0.931578  0.912692  0.831499   \n",
      "\n",
      "          177       178       179       180       181       182       183  \n",
      "0    0.923775  0.985842  0.862918  0.973597  0.938368  0.945639  0.932862  \n",
      "1    0.790636  0.883018  0.675884  0.972996  0.991783  0.988524  0.981167  \n",
      "2    0.864696  0.961228  0.775158  0.994931  0.989274  0.995966  0.987583  \n",
      "3    0.891424  0.969715  0.802688  0.997336  0.984975  0.991062  0.978269  \n",
      "4    0.768920  0.877347  0.655391  0.970741  0.992872  0.987236  0.986323  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "179  0.942702  0.858934  1.000000  0.791763  0.727605  0.745174  0.696908  \n",
      "180  0.883940  0.955488  0.791763  1.000000  0.989882  0.989944  0.979530  \n",
      "181  0.820336  0.919242  0.727605  0.989882  1.000000  0.994660  0.992953  \n",
      "182  0.839641  0.938761  0.745174  0.989944  0.994660  1.000000  0.991536  \n",
      "183  0.782923  0.922494  0.696908  0.979530  0.992953  0.991536  1.000000  \n",
      "\n",
      "[184 rows x 185 columns]\n",
      "IM      index         0         1         2         3         4         5  \\\n",
      "0        0  1.000000  0.907669  0.176090  0.702117  0.286608  0.490720   \n",
      "1        1  0.907669  1.000000  0.018354  0.921630  0.071288  0.220028   \n",
      "2        2  0.176090  0.018354  1.000000  0.022731  0.981050  0.879705   \n",
      "3        3  0.702117  0.921630  0.022731  1.000000  0.001701  0.042796   \n",
      "4        4  0.286608  0.071288  0.981050  0.001701  1.000000  0.952651   \n",
      "..     ...       ...       ...       ...       ...       ...       ...   \n",
      "656    656  0.399699  0.146881  0.933354  0.012895  0.983124  0.988453   \n",
      "657    657  0.170419  0.045495  0.956196  0.078107  0.926840  0.814243   \n",
      "658    658  0.895244  0.975839  0.045806  0.894017  0.099658  0.246381   \n",
      "659    659  0.016117  0.080791  0.834500  0.285888  0.722721  0.516941   \n",
      "660    660  0.031461  0.079063  0.845736  0.264039  0.740647  0.546501   \n",
      "\n",
      "            6         7         8  ...       651       652       653  \\\n",
      "0    0.719039  0.970476  0.852814  ...  0.018562  0.262593  0.080250   \n",
      "1    0.444454  0.974827  0.867932  ...  0.049907  0.506563  0.238188   \n",
      "2    0.684846  0.083677  0.195105  ...  0.876980  0.370412  0.650142   \n",
      "3    0.188250  0.817615  0.711285  ...  0.234733  0.753886  0.483892   \n",
      "4    0.803060  0.173261  0.276134  ...  0.775504  0.257325  0.525321   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "656  0.888592  0.274203  0.372869  ...  0.668887  0.180138  0.424284   \n",
      "657  0.622768  0.091308  0.197611  ...  0.891163  0.500563  0.749689   \n",
      "658  0.461533  0.956461  0.852942  ...  0.076113  0.548616  0.291475   \n",
      "659  0.282391  0.018094  0.093945  ...  0.995184  0.753412  0.942234   \n",
      "660  0.314889  0.025820  0.105386  ...  0.987390  0.741837  0.940644   \n",
      "\n",
      "          654       655       656       657       658       659       660  \n",
      "0    0.547275  0.022780  0.399699  0.170419  0.895244  0.016117  0.031461  \n",
      "1    0.808724  0.074212  0.146881  0.045495  0.975839  0.080791  0.079063  \n",
      "2    0.098734  0.846843  0.933354  0.956196  0.045806  0.834500  0.845736  \n",
      "3    0.970415  0.269916  0.012895  0.078107  0.894017  0.285888  0.264039  \n",
      "4    0.035068  0.740986  0.983124  0.926840  0.099658  0.722721  0.740647  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "656  0.008320  0.635777  1.000000  0.883281  0.181613  0.613177  0.642788  \n",
      "657  0.178040  0.889241  0.883281  1.000000  0.126786  0.859227  0.887914  \n",
      "658  0.794568  0.118486  0.181613  0.126786  1.000000  0.107377  0.124599  \n",
      "659  0.449486  0.995092  0.613177  0.859227  0.107377  1.000000  0.993158  \n",
      "660  0.424641  0.993029  0.642788  0.887914  0.124599  0.993158  1.000000  \n",
      "\n",
      "[661 rows x 662 columns]\n",
      "ID       id         0         1         2         3         4         5  \\\n",
      "0      1  1.000000  0.897662  0.969539  0.977718  0.895714  0.955645   \n",
      "1      2  0.897662  1.000000  0.973867  0.967525  0.998237  0.974889   \n",
      "2      3  0.969539  0.973867  1.000000  0.997122  0.973182  0.986712   \n",
      "3      4  0.977718  0.967525  0.997122  1.000000  0.964158  0.991381   \n",
      "4      5  0.895714  0.998237  0.973182  0.964158  1.000000  0.966592   \n",
      "..   ...       ...       ...       ...       ...       ...       ...   \n",
      "179  180  0.862918  0.675884  0.775158  0.802688  0.655391  0.796309   \n",
      "180  181  0.973597  0.972996  0.994931  0.997336  0.970741  0.991165   \n",
      "181  182  0.938368  0.991783  0.989274  0.984975  0.992872  0.980042   \n",
      "182  183  0.945639  0.988524  0.995966  0.991062  0.987236  0.986661   \n",
      "183  184  0.932862  0.981167  0.987583  0.978269  0.986323  0.962156   \n",
      "\n",
      "            6         7         8  ...       174       175       176  \\\n",
      "0    0.946404  0.989230  0.885793  ...  0.981128  0.981633  0.938121   \n",
      "1    0.990946  0.900367  0.992380  ...  0.892665  0.895908  0.813548   \n",
      "2    0.994273  0.963344  0.967592  ...  0.966367  0.959415  0.885173   \n",
      "3    0.990337  0.977575  0.954821  ...  0.972319  0.973149  0.905176   \n",
      "4    0.990725  0.890795  0.997502  ...  0.887712  0.885108  0.801731   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "179  0.738956  0.892354  0.626119  ...  0.847433  0.868224  0.956633   \n",
      "180  0.992870  0.970224  0.961541  ...  0.956411  0.962710  0.902469   \n",
      "181  0.998560  0.931316  0.989023  ...  0.925891  0.923723  0.857679   \n",
      "182  0.997835  0.944274  0.981751  ...  0.947118  0.939886  0.864105   \n",
      "183  0.991868  0.916459  0.988846  ...  0.931578  0.912692  0.831499   \n",
      "\n",
      "          177       178       179       180       181       182       183  \n",
      "0    0.923775  0.985842  0.862918  0.973597  0.938368  0.945639  0.932862  \n",
      "1    0.790636  0.883018  0.675884  0.972996  0.991783  0.988524  0.981167  \n",
      "2    0.864696  0.961228  0.775158  0.994931  0.989274  0.995966  0.987583  \n",
      "3    0.891424  0.969715  0.802688  0.997336  0.984975  0.991062  0.978269  \n",
      "4    0.768920  0.877347  0.655391  0.970741  0.992872  0.987236  0.986323  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "179  0.942702  0.858934  1.000000  0.791763  0.727605  0.745174  0.696908  \n",
      "180  0.883940  0.955488  0.791763  1.000000  0.989882  0.989944  0.979530  \n",
      "181  0.820336  0.919242  0.727605  0.989882  1.000000  0.994660  0.992953  \n",
      "182  0.839641  0.938761  0.745174  0.989944  0.994660  1.000000  0.991536  \n",
      "183  0.782923  0.922494  0.696908  0.979530  0.992953  0.991536  1.000000  \n",
      "\n",
      "[184 rows x 185 columns]\n",
      "IM       id         0         1         2         3         4         5  \\\n",
      "0      1  1.000000  0.907669  0.176090  0.702117  0.286608  0.490720   \n",
      "1      2  0.907669  1.000000  0.018354  0.921630  0.071288  0.220028   \n",
      "2      3  0.176090  0.018354  1.000000  0.022731  0.981050  0.879705   \n",
      "3      4  0.702117  0.921630  0.022731  1.000000  0.001701  0.042796   \n",
      "4      5  0.286608  0.071288  0.981050  0.001701  1.000000  0.952651   \n",
      "..   ...       ...       ...       ...       ...       ...       ...   \n",
      "656  657  0.399699  0.146881  0.933354  0.012895  0.983124  0.988453   \n",
      "657  658  0.170419  0.045495  0.956196  0.078107  0.926840  0.814243   \n",
      "658  659  0.895244  0.975839  0.045806  0.894017  0.099658  0.246381   \n",
      "659  660  0.016117  0.080791  0.834500  0.285888  0.722721  0.516941   \n",
      "660  661  0.031461  0.079063  0.845736  0.264039  0.740647  0.546501   \n",
      "\n",
      "            6         7         8  ...       651       652       653  \\\n",
      "0    0.719039  0.970476  0.852814  ...  0.018562  0.262593  0.080250   \n",
      "1    0.444454  0.974827  0.867932  ...  0.049907  0.506563  0.238188   \n",
      "2    0.684846  0.083677  0.195105  ...  0.876980  0.370412  0.650142   \n",
      "3    0.188250  0.817615  0.711285  ...  0.234733  0.753886  0.483892   \n",
      "4    0.803060  0.173261  0.276134  ...  0.775504  0.257325  0.525321   \n",
      "..        ...       ...       ...  ...       ...       ...       ...   \n",
      "656  0.888592  0.274203  0.372869  ...  0.668887  0.180138  0.424284   \n",
      "657  0.622768  0.091308  0.197611  ...  0.891163  0.500563  0.749689   \n",
      "658  0.461533  0.956461  0.852942  ...  0.076113  0.548616  0.291475   \n",
      "659  0.282391  0.018094  0.093945  ...  0.995184  0.753412  0.942234   \n",
      "660  0.314889  0.025820  0.105386  ...  0.987390  0.741837  0.940644   \n",
      "\n",
      "          654       655       656       657       658       659       660  \n",
      "0    0.547275  0.022780  0.399699  0.170419  0.895244  0.016117  0.031461  \n",
      "1    0.808724  0.074212  0.146881  0.045495  0.975839  0.080791  0.079063  \n",
      "2    0.098734  0.846843  0.933354  0.956196  0.045806  0.834500  0.845736  \n",
      "3    0.970415  0.269916  0.012895  0.078107  0.894017  0.285888  0.264039  \n",
      "4    0.035068  0.740986  0.983124  0.926840  0.099658  0.722721  0.740647  \n",
      "..        ...       ...       ...       ...       ...       ...       ...  \n",
      "656  0.008320  0.635777  1.000000  0.883281  0.181613  0.613177  0.642788  \n",
      "657  0.178040  0.889241  0.883281  1.000000  0.126786  0.859227  0.887914  \n",
      "658  0.794568  0.118486  0.181613  0.126786  1.000000  0.107377  0.124599  \n",
      "659  0.449486  0.995092  0.613177  0.859227  0.107377  1.000000  0.993158  \n",
      "660  0.424641  0.993029  0.642788  0.887914  0.124599  0.993158  1.000000  \n",
      "\n",
      "[661 rows x 662 columns]\n",
      "mirna_ids 184\n",
      "disease_ids 578\n",
      "# Drug = 184 | Mutation = 578\n",
      "# Test: Drug = 36 | Mutation = 115\n",
      "--------------------------n_neighbors =  1\n"
     ]
    }
   ],
   "source": [
    "\n",
    "for isbalance in [True]:\n",
    "    print('************isbalance = ', isbalance)\n",
    "    \n",
    "    #for task in ['Tp', 'Td', 'Tm']:\n",
    "    for task in ['Tp','Td', 'Tm']:\n",
    "        print('=================task = ', task)\n",
    "        \n",
    "        ID, IM, dtp, mirna_ids, disease_ids, mirna_test_num, disease_test_num, knn_x, label = obtain_data('C:/Users/Administrator/Desktop/图采样data/last data', isbalance)\n",
    "\n",
    "        if task == 'Tp':\n",
    "            train_index_all, test_index_all, train_id_all, test_id_all = generate_task_Tp_train_test_idx(knn_x)\n",
    "        elif task == 'Tm':\n",
    "            item = 'Drug'\n",
    "            ids = mirna_ids\n",
    "            train_index_all, test_index_all, train_id_all, test_id_all = generate_task_Tm_Td_train_test_idx(item, ids, dtp)\n",
    "        elif task == 'Td':\n",
    "            item = 'Mutation'\n",
    "            ids = disease_ids\n",
    "            train_index_all, test_index_all, train_id_all, test_id_all = generate_task_Tm_Td_train_test_idx(item, ids, dtp)\n",
    "\n",
    "        if isbalance:\n",
    "            balance = ''\n",
    "        else:\n",
    "            balance = '__nobalance'\n",
    "\n",
    "        np.savez_compressed('F:/graph data/' + task + balance + '__testlabel0_knn_edge_train_test_index_all.npz', \n",
    "                               train_index_all = train_index_all, \n",
    "                               test_index_all = test_index_all,\n",
    "                               train_id_all = train_id_all, \n",
    "                               test_id_all = test_id_all)\n",
    "\n",
    "        pwd = 'F:/graph data/'\n",
    "        for n_neigh in [1]: \n",
    "            print('--------------------------n_neighbors = ', n_neigh)\n",
    "            knn_x, knn_y, knn, knn_neighbors_graph = generate_knn_graph_save(knn_x, label, n_neigh, train_index_all, test_index_all, pwd, task, balance)\n",
    "directory='C:/Users/Administrator/Desktop/图采样data/last data'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "node_feature_label = pd.concat([dtp, knn_x], axis = 1)\n",
    "node_feature_label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pwd = 'F:/图采样实验数据/'\n",
    "node_feature_label.to_csv(pwd + 'node_feature_label.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
